//加载我的课程
function loadCourse() {
    var user = getLoginUser();
    console.log(user.id);
    let url = "/course/UserCourseInfo";
    let param = "userId=" + user.id;
    httpGet(url, param, function (data) {
        console.log(data);
        let templateCourseHtml = $("#template_course").html();
        let courseListHtml = "";
        let tempCourseHtml;
        //遍历商品列表
        $.each(data, function (index, course) {
            //后台数据填充到模板中
            tempCourseHtml = templateCourseHtml.replace("{name}", course.name)
                /*   .replace(/{des}/g, course.des)*/
                .replace(/{img}/g, course.img);
            courseListHtml += tempCourseHtml;
        });
        //拼接商品展示html
        //html 填充到页面当中
        $("#showPage").html(courseListHtml);
    });
}

//加载订单信息
function loadOrder() {
    var user = getLoginUser();
    let url = "/order/info";
    let param = "userId=" + user.id;
    httpGet(url, param, function (data) {
        let templateorderHtml = $("#template_order").html();
        $.each(data, function (index, order) {
            console.log("order.orderStatus is : " + order.orderStatus);
            if (order.orderStatus === 1) {       /*交易成功*/
                templateorderHtml = templateorderHtml + '<div style="font-family: \'Arial Black\';flood-color: #761c19">\n' +
                    '            <button class="btn btn-success" type="submit" style="width: 155px;border: black solid 1px;margin-left: 13px">{orderId}</button>\n' +
                    '            <button class="btn btn-primary" type="submit" style="border: black solid 1px;width: 110px">{courseId}</button>\n' +
                    '            <button class="btn btn-primary" type="submit" style="border: black solid 1px;width: 110px">{totalPrice}</button>\n' +
                    '            <button class="btn btn-success" type="submit" style="width: 205px;border: black solid 1px">{orderStatus}</button>\n' +
                    '        </div>';
                templateorderHtml = templateorderHtml.replace("{orderId}", order.orderId)
                    .replace("{courseId}", order.courseId)
                    .replace("{totalPrice}", order.totalPrice)
                    .replace("{orderStatus}", "交易成功");
            } else if (order.orderStatus === 0) {      /*待支付*/
                templateorderHtml = templateorderHtml + '<div style="font-family: \'Arial Black\';flood-color: #761c19">\n' +
                    '            <button class="btn btn-success" type="submit" style="width: 155px;border: black solid 1px;margin-left: 13px">{orderId}</button>\n' +
                    '            <button class="btn btn-primary" type="submit" style="border: black solid 1px;width: 110px">{courseId}</button>\n' +
                    '            <button class="btn btn-primary" type="submit" style="border: black solid 1px;width: 110px">{totalPrice}</button>\n' +
                    '            <button class="btn btn-warning" type="submit" style="width: 205px;border: black solid 1px">{orderStatus}</button>\n' +
                    '            <button class="btn btn-success" type="submit" style="width: 205px;border: black solid 1px" onclick="startOrder()">{payment}</button>\n' +
                    '        </div>';
                templateorderHtml = templateorderHtml.replace("{orderId}", order.orderId)
                    .replace("{courseId}", order.courseId)
                    .replace("{totalPrice}", order.totalPrice)
                    .replace("{orderStatus}", "待支付")
                    .replace("{payment}", "去支付→");
            } else if (order.orderStatus === -1) {         /*交易失败*/
                templateorderHtml = templateorderHtml + '<div style="font-family: \'Arial Black\';flood-color: #761c19">\n' +
                    '            <button class="btn btn-success" type="submit" style="width: 155px;border: black solid 1px;margin-left: 13px">{orderId}</button>\n' +
                    '            <button class="btn btn-primary" type="submit" style="border: black solid 1px;width: 110px">{courseId}</button>\n' +
                    '            <button class="btn btn-primary" type="submit" style="border: black solid 1px;width: 110px">{totalPrice}</button>\n' +
                    '            <button class="btn btn-danger" type="submit" style="width: 205px;border: black solid 1px">{orderStatus}</button>\n' +
                    '        </div>';
                templateorderHtml = templateorderHtml.replace("{orderId}", order.orderId)
                    .replace("{courseId}", order.courseId)
                    .replace("{totalPrice}", order.totalPrice)
                    .replace("{orderStatus}", "交易失败");
            }
        });
        //拼接订单展示html
        //html 填充到页面当中
        $("#showPage").html(templateorderHtml);
    });
}

//加载用户信息
function loadUser() {
    var user = getLoginUser();
    let url = "/user/info"
    let param = "userId=" + user.id;
    httpGet(url, param, function (data) {
        console.log(data);
        console.log(data.phone);
        let templateUserHtml = $("#template_userInfo").html();
        $("#showPage").html(templateUserHtml);
        $("#user_name").attr("value", data.name);
        $("#user_password").attr("value", data.password);
        $("#user_phone").attr("value", data.phone);
        $("#user_email").attr("value", data.email);
        $("#user_sex").attr("value", data.sex);
        $("#user_brith").attr("value", data.birth);
    });
}

function goLearn() {

}

//改变用户资料
function changeUsername() {
    alert("asdasd");
}

function changePassword() {

}

function changePhone() {

}

function changeEmail() {

}

function changeSex() {

}

function changeBirth() {

}